package com.sugar.real.estate.module.business.controller.app.apartment;

import com.sugar.real.estate.framework.common.pojo.CommonResult;
import com.sugar.real.estate.framework.common.pojo.PageParam;
import com.sugar.real.estate.framework.common.pojo.PageResult;
import com.sugar.real.estate.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.real.estate.module.business.controller.app.apartment.vo.AppApartmentDetailRespVO;
import com.sugar.real.estate.module.business.controller.app.apartment.vo.AppApartmentPageReqVO;
import com.sugar.real.estate.module.business.controller.app.apartment.vo.AppApartmentSimpleRespVO;
import com.sugar.real.estate.module.business.service.apartment.ApartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import java.util.List;

import static com.sugar.real.estate.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 楼盘/公寓")
@RestController
@RequestMapping("/biz/apartment")
@Validated
public class AppApartmentController {

    @Resource
    private ApartmentService apartmentService;

    @GetMapping("/get")
    @Operation(summary = "获得楼盘/公寓")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PermitAll
    public CommonResult<AppApartmentDetailRespVO> getApartment(@RequestParam("id") Long id) {
        return success(apartmentService.appGetApartment(id, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/page")
    @Operation(summary = "获得楼盘/公寓分页")
    @PermitAll
    public CommonResult<PageResult<AppApartmentSimpleRespVO>> getApartmentPage(@Valid AppApartmentPageReqVO pageReqVO) {
        return success(apartmentService.appGetApartmentPage(pageReqVO));
    }

    @GetMapping("/map")
    @Operation(summary = "地图查询公寓")
    @PermitAll
    public CommonResult<List<AppApartmentSimpleRespVO>> getApartmentListByMap(AppApartmentPageReqVO reqVO) {
        reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        return success(apartmentService.getApartmentListByMap(reqVO));
    }
}